<!doctype html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/54cz/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/54cz/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/54cz/css/main.css?v=5.1.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Hexo," />








  <link rel="shortcut icon" type="image/x-icon" href="/54cz/favicon.ico?v=5.1.1" />






<meta name="description" content="暑假开始了第一件事就是把博客搭建好,想着之后一边学习一边做笔记(以后回过头看的时候肯定很棒！)，说不定还能解决小伙伴们也遇到的问题，接下来进入正题开始搭建吧。  Hexo介绍Hexo是一个基于Node.js的快速、简洁且高效的博客框架。Hexo 使用 Markdown（或其他渲染引擎）解析文章，在几秒内，即可利用靓丽的主题生成静态网页，其生成的静态网页可以托管在Github上。  超快速度 支持M">
<meta name="keywords" content="Hexo">
<meta property="og:type" content="article">
<meta property="og:title" content="Hexo+github搭建个人博客">
<meta property="og:url" content="http://yoursite.com/2017/06/29/Hexo-github搭建个人博客/index.html">
<meta property="og:site_name" content="Orange">
<meta property="og:description" content="暑假开始了第一件事就是把博客搭建好,想着之后一边学习一边做笔记(以后回过头看的时候肯定很棒！)，说不定还能解决小伙伴们也遇到的问题，接下来进入正题开始搭建吧。  Hexo介绍Hexo是一个基于Node.js的快速、简洁且高效的博客框架。Hexo 使用 Markdown（或其他渲染引擎）解析文章，在几秒内，即可利用靓丽的主题生成静态网页，其生成的静态网页可以托管在Github上。  超快速度 支持M">
<meta property="og:image" content="http://yoursite.com/2017/06/29/Hexo-github搭建个人博客/hexo检查安装.png">
<meta property="og:image" content="http://yoursite.com/2017/06/29/Hexo-github搭建个人博客/hexo默认主题.png">
<meta property="og:image" content="http://yoursite.com/2017/06/29/Hexo-github搭建个人博客/创建.png">
<meta property="og:image" content="http://yoursite.com/2017/06/29/Hexo-github搭建个人博客/ssh位置.png">
<meta property="og:image" content="http://yoursite.com/2017/06/29/Hexo-github搭建个人博客/https地址.png">
<meta property="og:updated_time" content="2017-06-30T06:49:21.974Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Hexo+github搭建个人博客">
<meta name="twitter:description" content="暑假开始了第一件事就是把博客搭建好,想着之后一边学习一边做笔记(以后回过头看的时候肯定很棒！)，说不定还能解决小伙伴们也遇到的问题，接下来进入正题开始搭建吧。  Hexo介绍Hexo是一个基于Node.js的快速、简洁且高效的博客框架。Hexo 使用 Markdown（或其他渲染引擎）解析文章，在几秒内，即可利用靓丽的主题生成静态网页，其生成的静态网页可以托管在Github上。  超快速度 支持M">
<meta name="twitter:image" content="http://yoursite.com/2017/06/29/Hexo-github搭建个人博客/hexo检查安装.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/54cz/',
    scheme: 'Mist',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2017/06/29/Hexo-github搭建个人博客/"/>





  <title>Hexo+github搭建个人博客 | Orange</title>
  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?f44c8179266a8d1f51653650f2dee921";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>










</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/54cz/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Orange</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">这是副标题？.......</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/54cz/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/54cz/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/54cz/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/54cz/2017/06/29/Hexo-github搭建个人博客/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Orange">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/54cz/头像.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Orange">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Hexo+github搭建个人博客</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-06-29T11:47:30+08:00">
                2017-06-29
              </time>
            

            

            
          </span>

          

          
            
          

          
          
             <span id="/54cz/2017/06/29/Hexo-github搭建个人博客/" class="leancloud_visitors" data-flag-title="Hexo+github搭建个人博客">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数 </span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>暑假开始了第一件事就是把博客搭建好,想着之后一边学习一边做笔记(以后回过头看的时候肯定很棒！)，说不定还能解决小伙伴们也遇到的问题，接下来进入正题开始搭建吧。</p>
<hr>
<h1 id="Hexo介绍"><a href="#Hexo介绍" class="headerlink" title="Hexo介绍"></a>Hexo介绍</h1><p><a href="https://hexo.io/zh-cn/index.html" target="_blank" rel="external">Hexo</a>是一个基于Node.js的快速、简洁且高效的博客框架。Hexo 使用 Markdown（或其他渲染引擎）解析文章，在几秒内，即可利用靓丽的主题生成静态网页，其生成的静态网页可以托管在Github上。</p>
<ul>
<li>超快速度</li>
<li>支持MarkDown</li>
<li>一键部署</li>
<li>丰富的插件</li>
</ul>
<h1 id="环境准备"><a href="#环境准备" class="headerlink" title="环境准备"></a>环境准备</h1><h2 id="安装node-js"><a href="#安装node-js" class="headerlink" title="安装node.js"></a>安装node.js</h2><p>在<a href="https://nodejs.org/en/" target="_blank" rel="external">Nodejs官网</a>下载对应系统的安装包</p>
<p>安装详情可参照<a href="http://www.runoob.com/nodejs/nodejs-install-setup.html" target="_blank" rel="external">Node.js 安装配置</a></p>
<h2 id="安装git"><a href="#安装git" class="headerlink" title="安装git"></a>安装git</h2><p>在<a href="https://git-scm.com/" target="_blank" rel="external">git官网</a>下载对应系统的安装包</p>
<p>安装配置可参照<a href="http://blog.csdn.net/renfufei/article/details/41647875" target="_blank" rel="external">Git安装与配置</a></p>
<h1 id="安装Hexo"><a href="#安装Hexo" class="headerlink" title="安装Hexo"></a>安装Hexo</h1><p>首先创建一个文件夹,如hexo,用户存放hexo的配置文件,然后进入hexo里安装。</p>
<p>打开命令行(cmd)进入到hexo目录中,使用npm安装hexo。输入：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ npm install hexo-cli -g</div></pre></td></tr></table></figure></p>
<p>检查是否安装成功，命令行输入hexo如下面出现相应信息就说明成功了。</p>
<p><img src="/2017/06/29/Hexo-github搭建个人博客/hexo检查安装.png" alt=""></p>
<h2 id="初始化博客"><a href="#初始化博客" class="headerlink" title="初始化博客"></a>初始化博客</h2><p>接着还是在blog目录中输入<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">$ hexo init blog   //blog是文件夹名 如果你在c：/hexo中输入此命令 则会在hexo文件夹中生存一个blog文件夹</div><div class="line">$ cd blog  //进入blog文件夹</div><div class="line">$ npm install</div></pre></td></tr></table></figure></p>
<p>此时指定的文件夹目录如下：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">.</div><div class="line">├── _config.yml  //网站的配置信息</div><div class="line">├── package.json //应用程序的信息</div><div class="line">├── scaffolds //模版 文件夹</div><div class="line">├── source //资源文件夹是存放用户资源的地方。</div><div class="line">|   ├── _drafts</div><div class="line">|   └── _posts</div><div class="line">└── themes //主题文件夹</div></pre></td></tr></table></figure></p>
<h2 id="生成并预览"><a href="#生成并预览" class="headerlink" title="生成并预览"></a>生成并预览</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">$ hexo g  </div><div class="line">$ hexo s</div></pre></td></tr></table></figure>
<p>现在可以在(<a href="http://localhost:4000/" target="_blank" rel="external">http://localhost:4000/</a>) 进行预览了<br><img src="/2017/06/29/Hexo-github搭建个人博客/hexo默认主题.png" alt=""></p>
<h1 id="常用命令介绍"><a href="#常用命令介绍" class="headerlink" title="常用命令介绍"></a>常用命令介绍</h1><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">$ hexo generate == hexo g  //生成静态文件，会在当前目录下生成一个新的叫做public的文件夹</div><div class="line">$ hexo clean //清除你生成的静态文件</div><div class="line">$ hexo server == hexo s //启动本地web服务，用于博客的预览</div><div class="line">$ hexo deploy == hexo d //部署播客到远端（比如github, heroku等平台）</div><div class="line">$ hexo new 此处为文章名 //新建文章</div><div class="line">$ hexo d -g    //生成部署</div><div class="line">$ hexo s -g    //生成预览</div></pre></td></tr></table></figure>
<h1 id="部署到github"><a href="#部署到github" class="headerlink" title="部署到github"></a>部署到github</h1><h2 id="创建github仓库"><a href="#创建github仓库" class="headerlink" title="创建github仓库"></a>创建github仓库</h2><p>首先在<a href="https://github.com/" target="_blank" rel="external">github</a>上注册一个账号，登录后在点击右上角头像旁边的加号选择New repository<br><img src="/2017/06/29/Hexo-github搭建个人博客/创建.png" alt=""><br>Repository name 一定要填 你的账号名.github.io 例如：name.github.io 以后进入你的网站就是靠这个域名了</p>
<h2 id="生成添加ssh密钥"><a href="#生成添加ssh密钥" class="headerlink" title="生成添加ssh密钥"></a>生成添加ssh密钥</h2><p>打开命令行(cmd)输入<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ssh-keygen -t rsa -C &quot;Github的注册邮箱地址&quot; //注意这里C是大写</div></pre></td></tr></table></figure></p>
<p>然后一直回车就行了，会生成一个.ssh文件夹<br>位置在<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">C:\Users\user\.ssh</div></pre></td></tr></table></figure></p>
<p><img src="/2017/06/29/Hexo-github搭建个人博客/ssh位置.png" alt=""></p>
<p>找到id_rsa.pub这个文件，右键以记事本的方式打开，复制里面的全部内容</p>
<p>回到github点击右上角的头像选择Settings –&gt; SSH and GPG keys –&gt; new ssh key </p>
<p>将复制的内容粘贴到key中，随便写个Title点击add shh key就可以了</p>
<h2 id="修改配置文件"><a href="#修改配置文件" class="headerlink" title="修改配置文件"></a>修改配置文件</h2><p>进入初始化生成的目录找到_config.yml文件打开编辑在最后deploy中添加如下</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">deploy:</div><div class="line">  type: git</div><div class="line">  repo: //这里填仓库地址</div><div class="line">  branch: master</div></pre></td></tr></table></figure>
<p>repo填写新建好仓库的https链接</p>
<p><img src="https地址.png" alt=""></p>
<h2 id="部署"><a href="#部署" class="headerlink" title="部署"></a>部署</h2><p>安装 hexo-deployer-git<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">npm install hexo-deployer-git --save</div></pre></td></tr></table></figure></p>
<p>输入<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">hexo d</div></pre></td></tr></table></figure></p>
<p>等一小会，访问创建仓库时的Repository name就可以看到自己的网站了</p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/54cz/tags/Hexo/" rel="tag"># Hexo</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/54cz/2017/06/30/Android MVP/" rel="prev" title="Android MVP">
                Android MVP <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/54cz/头像.jpg"
               alt="Orange" />
          <p class="site-author-name" itemprop="name">Orange</p>
           
              <p class="site-description motion-element" itemprop="description">感觉要写点什么但又不知道写什么(╯｀□′)╯~ ╧╧</p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/54cz/archives/">
                <span class="site-state-item-count">2</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          

          
            
            
            <div class="site-state-item site-state-tags">
              
                <span class="site-state-item-count">3</span>
                <span class="site-state-item-name">标签</span>
              
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#Hexo介绍"><span class="nav-number">1.</span> <span class="nav-text">Hexo介绍</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#环境准备"><span class="nav-number">2.</span> <span class="nav-text">环境准备</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#安装node-js"><span class="nav-number">2.1.</span> <span class="nav-text">安装node.js</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#安装git"><span class="nav-number">2.2.</span> <span class="nav-text">安装git</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#安装Hexo"><span class="nav-number">3.</span> <span class="nav-text">安装Hexo</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#初始化博客"><span class="nav-number">3.1.</span> <span class="nav-text">初始化博客</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#生成并预览"><span class="nav-number">3.2.</span> <span class="nav-text">生成并预览</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#常用命令介绍"><span class="nav-number">4.</span> <span class="nav-text">常用命令介绍</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#部署到github"><span class="nav-number">5.</span> <span class="nav-text">部署到github</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#创建github仓库"><span class="nav-number">5.1.</span> <span class="nav-text">创建github仓库</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#生成添加ssh密钥"><span class="nav-number">5.2.</span> <span class="nav-text">生成添加ssh密钥</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#修改配置文件"><span class="nav-number">5.3.</span> <span class="nav-text">修改配置文件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#部署"><span class="nav-number">5.4.</span> <span class="nav-text">部署</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy;  2017 - 
  <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Orange</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  <script type="text/javascript" src="/54cz/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/54cz/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/54cz/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/54cz/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/54cz/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/54cz/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>

  
  <script type="text/javascript" src="/54cz/lib/canvas-nest/canvas-nest.min.js"></script>


  


  <script type="text/javascript" src="/54cz/js/src/utils.js?v=5.1.1"></script>

  <script type="text/javascript" src="/54cz/js/src/motion.js?v=5.1.1"></script>



  
  

  
  <script type="text/javascript" src="/54cz/js/src/scrollspy.js?v=5.1.1"></script>
<script type="text/javascript" src="/54cz/js/src/post-details.js?v=5.1.1"></script>



  


  <script type="text/javascript" src="/54cz/js/src/bootstrap.js?v=5.1.1"></script>



  


  




	





  





  





  






  





  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.1.js"></script>
  <script>AV.initialize("3JAuaY0g96wK9SfJshI3L6T9-gzGzoHsz", "1iDxrMdtKAUeFRcMGPYnYsA8");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  

  

  

</body>
</html>
